/**
* memberController Module
*
* memberController
*/
angular.module('app.con.member', []).controller('MemberController', function($scope, $modal, MemberService) {
	// ngView部分高度自适应
	var window_height = window.innerHeight - document.getElementsByTagName('nav')[0].offsetHeight - document.getElementsByTagName('footer')[0].offsetHeight;
	document.getElementById('ngView').style.height = window_height + 'px';

	//人员列表
	MemberService.list().success(function(res) {
		$scope.memberlist = res.memberlist;
	});

	//添加用户
	$scope.addMember = function() {
		addMemberModule = $modal.open({
			templateUrl: 'addMember.html',
			controller: 'AddMemberController'
		});
		addMemberModule.result.then(function(result) {
			console.log(result);
			$scope.memberlist.push(result);
		}, function(reason) {
			console.log(reason);
		});
	};

	$scope.deleteMember = function(num) {
		$scope.memberlist.splice(num, 1);
		MemberService.delete().success(function(res) {
			console.log(res);
		});
	};
});

angular.module('app.con.member.addMember', []).controller('AddMemberController', function($scope, $modalInstance, MemberService) {
	$scope.newMember = function() {
		var newMember = {
			username    : $scope.addMemberUsername,
			password    : $scope.addMemberPassword,
			department  : $scope.addMemberDepartment,
			reg_datetime: new Date()
		};

		MemberService.add().success(function(res) {
			console.log(res);
			console.log(newMember);
			$modalInstance.close(newMember);
		});
	};
});

